package com.guaoran.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.Random;
import java.util.UUID;

/**
 * @author : 孤傲然
 * @Description :
 * @date :2018/1/23 15:27
 */
public class StringUtils {
    /**
     * 获得随机数字
     * @return
     */
    public static String getRandomNum(){
        int random = new Random().nextInt(900000)+100000;
        return System.currentTimeMillis() + String.valueOf(random);
    }

    /**
     * 获得随机字符串
     * @return
     */
    public static String getRandomChar(){
        UUID uuid = UUID.randomUUID();
        int random = new Random().nextInt(90)+10;
        return uuid.toString().replaceAll("-","") + String.valueOf(random);
    }

    /**
     * json
     * @param object
     * @return
     */
    public static String toJson(Object object) {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setPrettyPrinting();
        Gson gson = gsonBuilder.create();
        return gson.toJson(object);
    }
}
